//
//  ChatBottomView.m
//  WChat
//
//  Created by lw on 2018/7/31.
//  Copyright © 2018年 mjsfax. All rights reserved.
//

#import "ChatBottomView.h"

@interface ChatBottomView()
@property (weak, nonatomic) IBOutlet UIButton *btnTalk;
@property (strong, nonatomic) ChatKeyboardView *keyboardView;
@property (assign, nonatomic) BOOL showFunctions;
@end

@implementation ChatBottomView

+ (instancetype)instance {
    return [[NSBundle mainBundle] loadNibNamed:@"ChatBottomView" owner:nil options:nil].firstObject;
}

- (void)awakeFromNib {
    self.btnTalk.hidden = YES;
    [self.btnTalk setTitle:@"松开 结束" forState:UIControlStateHighlighted];
    self.tfInpute.inputView.backgroundColor = [UIColor whiteColor];
    self.tfInpute.keyboardAppearance = UIKeyboardAppearanceLight;
}

- (IBAction)talk:(UIButton *)sender {
    sender.selected = !sender.isSelected;
    self.btnTalk.hidden = !self.btnTalk.hidden;
    self.tfInpute.hidden = !self.tfInpute.hidden;
    if (!self.btnTalk.hidden) {
        [self.tfInpute resignFirstResponder];
    }
}

//按下
- (IBAction)down:(UIButton *)sender {
    NSLog(@"down");
    if (self.inputBlock) {
        self.inputBlock(MessageTypeSpeaking);
    }

}
//抬起
- (IBAction)touchUpInside:(UIButton *)sender {
    NSLog(@"up inside");
    if (self.inputBlock) {
        self.inputBlock(MessageTypeSend);
    }
}

- (IBAction)touchUpOutside:(UIButton *)sender {
    NSLog(@"up outside");
}
//按住过程中
- (IBAction)touchDragInside:(UIButton *)sender {
    NSLog(@"drag inside");
}
- (IBAction)touchDragOutside:(UIButton *)sender {
    NSLog(@"drag outside");
}

- (IBAction)emoji:(id)sender {
    
}

- (IBAction)function:(id)sender {
    
    self.showFunctions = !self.showFunctions;
    
    if (self.showFunctions) {
        self.tfInpute.inputView = self.keyboardView;
    } else {
        self.tfInpute.inputView = nil;
    }
    [self.tfInpute reloadInputViews];
    [self.tfInpute becomeFirstResponder];
    
}

- (ChatKeyboardView *)keyboardView {
    if (!_keyboardView) {
        _keyboardView = [[ChatKeyboardView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 200)];
        [UIApplication sharedApplication].keyWindow.backgroundColor = [UIColor whiteColor];
        __weak typeof(self)weakSelf = self;
        _keyboardView.actionBlock = ^(KeyboardType type) {
            if (weakSelf.functionBlock) {
                weakSelf.functionBlock(type);
            }
        };
    }
    return _keyboardView;
}

@end
